package com.oracle.calllog.analyze.model;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;

public class ContactDimBean implements WritableComparable<ContactDimBean>{
    // 手机号码
    private String callNo;
    // 持卡人姓名
    private String callName;
    // 日期维度分为三种情况:
    // 1.年份维度(年份数据正常,但月和日数据为0)
    // 2.月份维度(年份月份数据正常,但日数据为0)
    // 3.日份维度(年份月份日份数据都正常)
    private String yearDimension;
    private String monthDimension;
    private String dayDimension;

    public String getCallNo() {
        return callNo;
    }

    public void setCallNo(String callNo) {
        this.callNo = callNo;
    }

    public String getCallName() {
        return callName;
    }

    public void setCallName(String callName) {
        this.callName = callName;
    }

    public String getYearDimension() {
        return yearDimension;
    }

    public void setYearDimension(String yearDimension) {
        this.yearDimension = yearDimension;
    }

    public String getMonthDimension() {
        return monthDimension;
    }

    public void setMonthDimension(String monthDimension) {
        this.monthDimension = monthDimension;
    }

    public String getDayDimension() {
        return dayDimension;
    }

    public void setDayDimension(String dayDimension) {
        this.dayDimension = dayDimension;
    }



    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(this.callNo);
        out.writeUTF(this.callName);
        out.writeUTF(this.yearDimension);
        out.writeUTF(this.monthDimension);
        out.writeUTF(this.dayDimension);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.callNo = in.readUTF();
        this.callName = in.readUTF();
        this.yearDimension = in.readUTF();
        this.monthDimension = in.readUTF();
        this.dayDimension = in.readUTF();
    }

    @Override
    public int compareTo(ContactDimBean other) {
        int result = this.callNo.compareTo(other.callNo);
        if(result==0) {
            result = this.yearDimension.compareTo(other.getYearDimension());
            if(result==0) {
                result = this.monthDimension.compareTo(other.monthDimension);
                if(result==0) {
                    result = this.dayDimension.compareTo(other.dayDimension);
                }
            }
        }
        return result;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append(this.yearDimension)
                .append("\t").append(this.monthDimension)
                .append("\t").append(this.dayDimension)
                .append("\t").append(this.callNo)
                .append("\t").append(this.callName);

        return builder.toString();
    }
}
